package meicai.appium.utils;

import java.util.ArrayList;
import java.util.List;
import java.lang.String;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class GetCommandJsonFromHttp {
	
	public Log logger;
	
	public  GetCommandJsonFromHttp () {
		logger = Log.getLogger(GetCommandJsonFromHttp.class);
	}
	
	/*
	   {
		  "home_mark" : "item_name$0",
		  "metadata_list" : [
		    {
		      "mark" : "iv_plus$list",
		      "reproduction_step" : ["item_name$1","cate_tv$list", "iv_plus$list"],
		      "reproduction_explain" : "二级分类下无加购数据"
		    },
		    {
		      "mark" : "tv_choose_specifications$list",
		      "reproduction_step" : ["item_name$1","cate_tv$list", "tv_choose_specifications$list"],
		      "reproduction_explain" : "二级分类下无可以选规格的数据"
		    }
		  ]
		} 
	 */
	public List<JSONArray> getReproductioStepJsonArrayList() {
		
		String testcaseStrOne = HttpRequestUtils.httpGet(Constant.urlForTestCase);
		
		logger.debug(testcaseStrOne);
		
		String testCaseStr = "{\"medadata_list\":[{\"mark\":\"iv_plus$list\",\"reproduction_step\":"
				+ "[\"item_name$1\",\"cate_tv$list\",\"iv_plus$list\"],\"reproduction_explain\" : \"二级分类下无加购数据\"},"
				+ "{\"mark\" : \"tv_choose_specifications$list\",\"reproduction_step\" : [\"item_name$1\",\"cate_tv$list\", \"tv_choose_specifications$list\"],"
				+ "\"reproduction_explain\" : \"二级分类下无可以选规格的数据\"}]}";
		
		List<JSONArray> reproductionStepJsonArrayListTemp = new ArrayList<JSONArray>();
		JSONObject testCaseJson = JSON.parseObject(testCaseStr);
		JSONArray metadataArray = testCaseJson.getJSONArray("medadata_list");
		
		logger.debug("metadata_list size === " + metadataArray.size());
		for(int i = 0; i < metadataArray.size(); i++) {
			JSONArray reproduction_step = metadataArray.getJSONObject(i).getJSONArray("reproduction_step");
			reproductionStepJsonArrayListTemp.add(reproduction_step);
		}
		return reproductionStepJsonArrayListTemp;
	}
}
